<?php defined('SYSPATH') or die('No direct script access.');

class Model_Gallery extends ORM {	
		
	public static function insertImageInfo($name){
		return DB::query(Database::INSERT, "INSERT INTO galleries(name,tstamp) VALUES('".$name."','".time()."')")->execute();			
	}	
	
	public static function deleteItem($id){		
		// ORM::factory('gallery')->delete($id);		
		return DB::query(Database::DELETE, "DELETE FROM galleries WHERE id='".intval($id)."' LIMIT 1")->execute();	
	}	
	
	public static function getImageInfo($id){
		return DB::select()
		->from('galleries')
		->where('id', '=', $id)  
		->execute()->as_array(); 	
	}
	
	public static function itemsList($offset, $rowsPerPage){		   
		  return ORM::factory('gallery')->offset($offset)->limit($rowsPerPage)->find_all();		  
		  // return DB::query(Database::SELECT, "SELECT * FROM galleries WHERE 1=1
		 // order by id DESC LIMIT ".$offset.', '.$rowsPerPage)->execute()->as_array();	  	      
	}
	
	public static function getCountItems(){		  
		   return DB::query(Database::SELECT, "SELECT id FROM galleries")->execute()->count();	  	      
	}

}
